package com.onekbase.demo.mybatis;

import java.sql.*;

public class JdbcStatementDemo {
    public static void main(String[] args) {
        try (Connection conn = DbFactory.getConnection()) {
            String sql = "select * from sys_config ";
            try (Statement stmt = conn.createStatement(); ResultSet rs = stmt.executeQuery(sql)) {
                while (rs.next()) {
                    String ckey = rs.getString("ckey");
                    String cvalue = rs.getString("cvalue");
                    System.out.println(ckey + ":" + cvalue);
                }
            }
            System.out.println("PreparedStatement query");
            String sql2 = "select * from sys_config where ckey = ? ";
            try (PreparedStatement ps = conn.prepareStatement(sql2)) {
                ps.setString(1, "key.hello");
                try (ResultSet rs = ps.executeQuery()) {
                    while (rs.next()) {
                        String ckey = rs.getString("ckey");
                        String cvalue = rs.getString("cvalue");
                        System.out.println(ckey + ":" + cvalue);
                    }
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
